package com.gitee.cui.client.sender;

import com.gitee.cui.client.builder.ChatMsgBuilder;
import com.gitee.cui.common.common.bean.ChatMsg;
import com.gitee.cui.common.common.bean.msg.ProtoMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 *  发送聊天消息
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/27 15:34
 **/
@Slf4j
@Service
public class ChatSender extends BaseSender {

    /**
     * 发送聊天消息
     * @param toUserId 发送给用户id
     * @param message 消息
     */
    public void sendChatMsg(String toUserId, String message) {
        log.info("发送消息 startConnectServer");
        ChatMsg chatMsg = new ChatMsg(getUser());
        chatMsg.setContent(message);
        chatMsg.setMsgType(ChatMsg.MSGTYPE.TEXT);
        chatMsg.setTo(toUserId);
        chatMsg.setMsgId(System.currentTimeMillis());
        ProtoMsg.Message chatMessage = ChatMsgBuilder.buildChatMsg(chatMsg, getUser(), getSession());
        super.sendMsg(chatMessage);
    }

    @Override
    protected void sendFailed(ProtoMsg.Message message) {
        log.info("发送失败：" + message.getMessageRequest().getContent());
    }

    @Override
    protected void sendSuccess(ProtoMsg.Message message) {
        log.info("发送成功：" + message.getMessageRequest().getContent());
    }
}
